using System;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.Network;
using OracleInternal.Secure.Logon;
using OracleInternal.ServiceObjects;

namespace OracleInternal.TTC
{
	internal class TTCAuthenticate : TTCFunction
	{
		private const int TTCC_LNG = 254;

		internal const int KPZ_LOGON = 1;

		internal const int KPZ_CPW = 2;

		private const int KPZ_PROXY_AUTH = 1024;

		private const int KPZ_PASSWD_ENCRYPTED = 256;

		internal const int KPZ_LOGON_SYSDBA = 32;

		internal const int KPZ_LOGON_SYSOPER = 64;

		internal const int KPZ_LOGON_SYSASM = 4194304;

		internal const int KPZ_LOGON_SYSBKP = 16777216;

		internal const int KPZ_LOGON_SYSDGD = 33554432;

		internal const int KPZ_LOGON_SYSKMT = 67108864;

		internal const int KPZ_LOGON_SYSRAC = 134217728;

		internal const int KPZ_CPW_AUTH = 16;

		internal const int KPZ_OPASSWD_ENCRYPTED = 32;

		internal const int KPZ_NPASSWD_ENCRYPTED = 64;

		internal const int KPZ_NPASSWD_OBFUSCATE = 65536;

		private const int KPZ_LOGON_PRELIMAUTH = 128;

		internal const int KOLRUG_ENABLE = 1;

		internal const int KOLRUG_NSURWT = 16;

		internal const int KOLRUG_LOCMAP = 32;

		internal const int KOLRUG_CLNRCE = 64;

		internal const int KZTV_MAX_SALTL = 16;

		internal const int PBKDF2_VGEN_COUNT_MIN = 4096;

		internal const int PBKDF2_VGEN_COUNT_DEFAULT = 4096;

		internal const int PBKDF2_VGEN_COUNT_MAX = 100000000;

		internal const int PBKDF2_SDER_COUNT_MIN = 3;

		internal const int PBKDF2_SDER_COUNT_DEFAULT = 3;

		internal const int PBKDF2_SDER_COUNT_MAX = 100000000;

		private const string AUTH_PBKDF2_CSK_SALT = "AUTH_PBKDF2_CSK_SALT";

		private const string AUTH_PBKDF2_SDER_COUNT = "AUTH_PBKDF2_SDER_COUNT";

		private const string AUTH_PBKDF2_VGEN_COUNT = "AUTH_PBKDF2_VGEN_COUNT";

		private const string AUTH_PBKDF2_SPEEDY_KEY = "AUTH_PBKDF2_SPEEDY_KEY";

		private byte[] m_auth_pbkdf2_csk_salt;

		private byte[] m_auth_pbkdf2_sder_count;

		private byte[] m_auth_pbkdf2_vgen_count;

		private byte[] m_auth_pbkdf2_speedy_key;

		private byte[] m_pbkdf2_cskSalt;

		private int m_pbkdf2_vgen_count;

		private int m_pbkdf2_sder_count;

		private static char[] m_versionSeparator;

		private const string DOUBLE_QUOTE = "\"";

		internal const string AUTH_VERSION_NO = "AUTH_VERSION_NO";

		private const string AUTH_TERMINAL = "AUTH_TERMINAL";

		private const string AUTH_PROGRAM_NM = "AUTH_PROGRAM_NM";

		private const string AUTH_MACHINE = "AUTH_MACHINE";

		private const string AUTH_PID = "AUTH_PID";

		private const string AUTH_SID = "AUTH_SID";

		private const string AUTH_PASSWORD = "AUTH_PASSWORD";

		private const string AUTH_NEWPASSWORD = "AUTH_NEWPASSWORD";

		private const string AUTH_SESSKEY = "AUTH_SESSKEY";

		private const string AUTH_VFR_DATA = "AUTH_VFR_DATA";

		private const string AUTH_SVR_RESPONSE = "AUTH_SVR_RESPONSE";

		private const string AUTH_ALTER_SESSION = "AUTH_ALTER_SESSION";

		private const string AUTH_PROXY_CLIENT_NAME = "PROXY_CLIENT_NAME";

		private const string AUTH_CONNECT_STRING = "AUTH_CONNECT_STRING";

		internal const string AUTH_SERIAL_NUM = "AUTH_SERIAL_NUM";

		internal const string AUTH_SESSION_ID = "AUTH_SESSION_ID";

		internal const string AUTH_ORA_DEBUG_JDWP = "AUTH_ORA_DEBUG_JDWP";

		internal const string AUTH_ORA_EDITION = "AUTH_ORA_EDITION";

		internal const string AUTH_INSTANCENAME = "AUTH_INSTANCENAME";

		internal const string AUTH_DBNAME = "AUTH_DBNAME";

		internal const string AUTH_INSTANCE_NO = "AUTH_INSTANCE_NO";

		internal const string AUTH_FAILOVER_TYPE = "AUTH_FAILOVER_TYPE";

		internal const string AUTH_DB_MOUNT_ID = "AUTH_DB_MOUNT_ID";

		internal const string AUTH_DB_MOUNT_ID2 = "AUTH_DB_MOUNT_ID\0";

		internal const string AUTH_DB_ID = "AUTH_DB_ID";

		internal const string AUTH_DB_ID2 = "AUTH_DB_ID\0";

		internal const string AUTH_PDB_UID = "AUTH_PDB_UID";

		internal const string AUTH_PDB_UID2 = "AUTH_PDB_UID\0";

		internal const string AUTH_GLOBALLY_UNIQUE_DBID = "AUTH_GLOBALLY_UNIQUE_DBID";

		internal const string AUTH_GLOBALLY_UNIQUE_DBID2 = "AUTH_GLOBALLY_UNIQUE_DBID\0";

		internal const string AUTH_SC_SERVER_HOST = "AUTH_SC_SERVER_HOST";

		internal const string AUTH_SC_INSTANCE_NAME = "AUTH_SC_INSTANCE_NAME";

		internal const string AUTH_SC_INSTANCE_ID = "AUTH_SC_INSTANCE_ID";

		internal const string AUTH_SC_INSTANCE_START_TIME = "AUTH_SC_INSTANCE_START_TIME";

		internal const string AUTH_SC_DBUNIQUE_NAME = "AUTH_SC_DBUNIQUE_NAME";

		internal const string AUTH_SC_DB_DOMAIN = "AUTH_SC_DB_DOMAIN";

		internal const string AUTH_SC_SERVICE_NAME = "AUTH_SC_SERVICE_NAME";

		internal const string AUTH_SC_SVC_FLAGS = "AUTH_SC_SVC_FLAGS";

		internal const string AUTH_ONS_CONFIG = "AUTH_ONS_CONFIG";

		internal const string AUTH_ONS_RLB_SUBSCR_PATTERN = "AUTH_ONS_RLB_SUBSCR_PATTERN";

		internal const string AUTH_ONS_HA_SUBSCR_PATTERN = "AUTH_ONS_HA_SUBSCR_PATTERN";

		internal const string AUTH_MAX_OPEN_CURSORS = "AUTH_MAX_OPEN_CURSORS";

		internal const string AUTH_MAX_IDEN_LENGTH = "AUTH_MAX_IDEN_LENGTH";

		internal const string AUTH_SESSION_CLIENT_CSET = "SESSION_CLIENT_CHARSET";

		internal const string AUTH_SESSION_CLIENT_LTYPE = "SESSION_CLIENT_LIB_TYPE";

		internal const string AUTH_SESSION_CLIENT_DRVNM = "SESSION_CLIENT_DRIVER_NAME";

		internal const string AUTH_SESSION_CLIENT_VSN = "SESSION_CLIENT_VERSION";

		private const string SESSION_CLIENT_LOBATTR = "SESSION_CLIENT_LOBATTR";

		internal const string AUTH_NLS_LXLAN = "AUTH_NLS_LXLAN";

		internal const string AUTH_NLS_LXCTERRITORY = "AUTH_NLS_LXCTERRITORY";

		internal const string AUTH_NLS_LXCCURRENCY = "AUTH_NLS_LXCCURRENCY";

		internal const string AUTH_NLS_LXCISOCURR = "AUTH_NLS_LXCISOCURR";

		internal const string AUTH_NLS_LXCNUMERICS = "AUTH_NLS_LXCNUMERICS";

		internal const string AUTH_NLS_LXCDATEFM = "AUTH_NLS_LXCDATEFM";

		internal const string AUTH_NLS_LXCDATELANG = "AUTH_NLS_LXCDATELANG";

		internal const string AUTH_NLS_LXCSORT = "AUTH_NLS_LXCSORT";

		internal const string AUTH_NLS_LXCCALENDAR = "AUTH_NLS_LXCCALENDAR";

		internal const string AUTH_NLS_LXCUNIONCUR = "AUTH_NLS_LXCUNIONCUR";

		internal const string AUTH_NLS_LXCTIMEFM = "AUTH_NLS_LXCTIMEFM";

		internal const string AUTH_NLS_LXCSTMPFM = "AUTH_NLS_LXCSTMPFM";

		internal const string AUTH_NLS_LXCTTZNFM = "AUTH_NLS_LXCTTZNFM";

		internal const string AUTH_NLS_LXCSTZNFM = "AUTH_NLS_LXCSTZNFM";

		private const string AUTH_KPPL_CONN_CLASS = "AUTH_KPPL_CONN_CLASS";

		private const string AUTH_KPPL_PURITY = "AUTH_KPPL_PURITY";

		private const string AUTH_KPPL_TAG = "AUTH_KPPL_TAG";

		private const string AUTH_KPPL_IS_MULTIPROP_TAG = "AUTH_KPPL_IS_MULTIPROP_TAG";

		private const string AUTH_KPPL_FIXUP_CB = "AUTH_KPPL_FIXUP_CB";

		private const string AUTH_KPPL_WAIT = "AUTH_KPPL_WAIT";

		private const string KPPL_PURITY_DEFAULT = "0";

		private const string KPPL_PURITY_NEW = "1";

		private const string KPPL_PURITY_SELF = "2";

		private const string SESS_PURITY_DEFAULT = "DEFAULT";

		private const string SESS_PURITY_NEW = "NEW";

		private const string SESS_PURITY_SELF = "SELF";

		private const string SESSION_CLIENT_LIB_TYPE_VALUE = "0";

		internal const string SESSION_TIME_ZONE = "SESSION_TIME_ZONE";

		internal const string SESSION_NLS_LXCCHARSET = "SESSION_NLS_LXCCHARSET";

		internal const string SESSION_NLS_LXCNLSLENSEM = "SESSION_NLS_LXCNLSLENSEM";

		internal const string SESSION_NLS_LXCNCHAREXCP = "SESSION_NLS_LXCNCHAREXCP";

		internal const string SESSION_NLS_LXCNCHARIMP = "SESSION_NLS_LXCNCHARIMP";

		private const string CLIENT_DRIVER_NAME = "ODPC.NET";

		private byte[] m_authTerminal;

		private byte[] m_authProgramName;

		private byte[] m_authMachine;

		private byte[] m_authPid;

		private byte[] m_authSid;

		private byte[] m_authPassword;

		private byte[] m_authNewPassword;

		private byte[] m_authSessionKey;

		private byte[] m_authVerifierData;

		private byte[] m_authAlterSession;

		private byte[] m_authProxyClientName;

		private byte[] m_authSessionId;

		private byte[] m_authSerialNum;

		private byte[] m_authDebugJDWPValue;

		private byte[] m_authConnectString;

		private byte[] m_sessionClientCharSet;

		private byte[] m_sessionClientLibType;

		private byte[] m_sessionClientDriverName;

		private byte[] m_sessionClientVersion;

		private byte[] m_sessionClientLobAttr;

		private byte[] m_authOraEditionAttr;

		private byte[] m_drcpConnectionClass;

		private byte[] m_drcpTag;

		private byte[] m_drcpMultipropTag;

		private byte[] m_drcpSessionPurity;

		private byte[] m_drcpFixupCB;

		private static byte[] KZSR_SVR_RESPONSE;

		private static byte[] KZSR_CLI_RESPONSE;

		private static byte[] m_clientLobAttr;

		internal Hashtable m_sessionProperties;

		private byte[] m_terminalName;

		private byte[] m_programName;

		private byte[] m_hostName;

		private byte[] m_userName;

		private byte[] m_processId;

		private byte[] m_connectstring;

		private byte[] m_clientCharSet;

		private byte[] m_clientLibType;

		private byte[] m_clientDriverName;

		private byte[] m_clientVersion;

		private byte[] m_encryptedSK;

		private byte[] m_alterSessionSql;

		private int m_verifierType;

		private byte[] m_salt;

		private byte[] m_encryptedKB;

		internal byte[] m_xoredKaAndKb;

		private byte[] m_conFounder;

		private byte[] m_encryptedPassword;

		private byte[] m_newEncryptedPassword;

		private byte[] m_pbkdf2_speedy_key;

		static TTCAuthenticate()
		{
			m_versionSeparator = new char[1]
			{
				'.'
			};
			KZSR_SVR_RESPONSE = new byte[16]
			{
				83,
				69,
				82,
				86,
				69,
				82,
				95,
				84,
				79,
				95,
				67,
				76,
				73,
				69,
				78,
				84
			};
			KZSR_CLI_RESPONSE = new byte[16]
			{
				67,
				76,
				73,
				69,
				78,
				84,
				95,
				84,
				79,
				95,
				83,
				69,
				82,
				86,
				69,
				82
			};
			m_clientLobAttr = new byte[1]
			{
				49
			};
		}

		[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
		internal TTCAuthenticate(MarshallingEngine marshallingEngine, int lcid)
			: base(marshallingEngine, 118, 0)
		{
			m_authTerminal = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_TERMINAL", 0, "AUTH_TERMINAL".Length);
			m_authProgramName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PROGRAM_NM", 0, "AUTH_PROGRAM_NM".Length);
			m_authMachine = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_MACHINE", 0, "AUTH_MACHINE".Length);
			m_authPid = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PID", 0, "AUTH_PID".Length);
			m_auth_pbkdf2_csk_salt = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PBKDF2_CSK_SALT", 0, "AUTH_PBKDF2_CSK_SALT".Length);
			m_auth_pbkdf2_sder_count = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PBKDF2_SDER_COUNT", 0, "AUTH_PBKDF2_SDER_COUNT".Length);
			m_auth_pbkdf2_vgen_count = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PBKDF2_VGEN_COUNT", 0, "AUTH_PBKDF2_VGEN_COUNT".Length);
			m_auth_pbkdf2_speedy_key = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PBKDF2_SPEEDY_KEY", 0, "AUTH_PBKDF2_SPEEDY_KEY".Length);
			m_authSid = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_SID", 0, "AUTH_SID".Length);
			m_authPassword = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_PASSWORD", 0, "AUTH_PASSWORD".Length);
			m_authNewPassword = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_NEWPASSWORD", 0, "AUTH_NEWPASSWORD".Length);
			m_authDebugJDWPValue = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_ORA_DEBUG_JDWP", 0, "AUTH_ORA_DEBUG_JDWP".Length);
			m_authSessionKey = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_SESSKEY", 0, "AUTH_SESSKEY".Length);
			m_authVerifierData = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_VFR_DATA", 0, "AUTH_VFR_DATA".Length);
			m_authAlterSession = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_ALTER_SESSION", 0, "AUTH_ALTER_SESSION".Length);
			m_authProxyClientName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("PROXY_CLIENT_NAME", 0, "PROXY_CLIENT_NAME".Length);
			m_authSessionId = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_SESSION_ID", 0, "AUTH_SESSION_ID".Length);
			m_authSerialNum = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_SERIAL_NUM", 0, "AUTH_SERIAL_NUM".Length);
			m_authConnectString = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_CONNECT_STRING", 0, "AUTH_CONNECT_STRING".Length);
			m_sessionClientCharSet = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("SESSION_CLIENT_CHARSET", 0, "SESSION_CLIENT_CHARSET".Length);
			m_sessionClientLibType = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("SESSION_CLIENT_LIB_TYPE", 0, "SESSION_CLIENT_LIB_TYPE".Length);
			m_sessionClientDriverName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("SESSION_CLIENT_DRIVER_NAME", 0, "SESSION_CLIENT_DRIVER_NAME".Length);
			m_sessionClientVersion = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("SESSION_CLIENT_VERSION", 0, "SESSION_CLIENT_VERSION".Length);
			m_sessionClientLobAttr = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("SESSION_CLIENT_LOBATTR", 0, "SESSION_CLIENT_LOBATTR".Length);
			m_authOraEditionAttr = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_ORA_EDITION", 0, "AUTH_ORA_EDITION".Length);
			m_drcpConnectionClass = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_KPPL_CONN_CLASS", 0, "AUTH_KPPL_CONN_CLASS".Length);
			m_drcpTag = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_KPPL_TAG", 0, "AUTH_KPPL_TAG".Length);
			m_drcpMultipropTag = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_KPPL_IS_MULTIPROP_TAG", 0, "AUTH_KPPL_IS_MULTIPROP_TAG".Length);
			m_drcpSessionPurity = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_KPPL_PURITY", 0, "AUTH_KPPL_PURITY".Length);
			m_drcpFixupCB = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("AUTH_KPPL_FIXUP_CB", 0, "AUTH_KPPL_FIXUP_CB".Length);
			m_terminalName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("unknown", 0, "unknown".Length);
			m_programName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(ConfigBaseClass.ApplicationName + "." + ConfigBaseClass.CoreRunTimeExt, 0, (ConfigBaseClass.ApplicationName + "." + ConfigBaseClass.CoreRunTimeExt).Length);
			string text = Environment.MachineName;
			string userDomainName = Environment.UserDomainName;
			m_terminalName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text, 0, Environment.MachineName.Length);
			if (!string.IsNullOrWhiteSpace(userDomainName))
			{
				text = userDomainName + "\\" + text;
			}
			m_hostName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text, 0, text.Length);
			if (!string.IsNullOrEmpty(Environment.UserName))
			{
				m_userName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(Environment.UserName, 0, Environment.UserName.Length);
			}
			string text2 = ConfigBaseClass.CurrentProcess.Id + ":" + AppDomain.CurrentDomain.Id;
			m_processId = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text2, 0, text2.Length);
			string connectDescriptor = m_marshallingEngine.m_oracleCommunication.ConnectDescriptor;
			m_connectstring = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(connectDescriptor, 0, connectDescriptor.Length);
			string text3 = ClientVersionStringToInt(ConfigBaseClass.m_assemblyVersion.ToString()).ToString();
			m_clientVersion = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text3, 0, text3.Length);
			string[] array = ConfigBaseClass.m_assemblyVersion.ToString().Split('.');
			string str = ((array.Length > 2) ? array[2] : "0");
			string str2 = ((array.Length > 3) ? array[3] : "0");
			string str3 = str + "." + str2 + ".0.0.0";
			string text4 = "ODPC.NET" + " : " + str3;
			m_clientDriverName = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text4, 0, text4.Length);
			string text5 = 2002.ToString();
			m_clientCharSet = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text5, 0, text5.Length);
			m_clientLibType = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("0", 0, "0".Length);
			m_marshallingEngine.m_connImplReference.m_sessionTimeZone.initialZoneId = 0;
			string text6 = OracleGlobalizationImpl.CreateAlterSessionBlockForOAUTH(lcid, ref m_marshallingEngine.m_connImplReference.m_sessionTimeZone.initialZoneId);
			m_alterSessionSql = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text6, 0, text6.Length);
			m_alterSessionSql[m_alterSessionSql.Length - 1] = 0;
		}

		internal void ReInit(MarshallingEngine marshallingEngine, int lcid)
		{
			base.ReInit(marshallingEngine);
			m_encryptedSK = null;
			m_verifierType = 0;
			m_salt = null;
			m_encryptedKB = null;
			m_xoredKaAndKb = null;
			m_conFounder = null;
			m_encryptedPassword = null;
			m_newEncryptedPassword = null;
			m_marshallingEngine.m_connImplReference.m_sessionTimeZone.initialZoneId = 0;
			OracleGlobalizationImpl.CreateAlterSessionBlockForOAUTH(lcid, ref m_marshallingEngine.m_connImplReference.m_sessionTimeZone.initialZoneId);
		}

		internal void WriteOSessKeyMessage(string userName, long logonMode)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOSessKeyMessage);
			}
			try
			{
				byte[] array = null;
				if (!string.IsNullOrEmpty(userName))
				{
					array = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(userName, 0, userName.Length);
				}
				m_functionCode = 118;
				WriteFunctionHeader();
				m_marshallingEngine.MarshalPointer();
				if (array != null)
				{
					m_marshallingEngine.MarshalSB4(array.Length);
				}
				else
				{
					m_marshallingEngine.MarshalSB4(0);
				}
				m_marshallingEngine.MarshalUB4(logonMode | 1);
				m_marshallingEngine.MarshalPointer();
				byte[][] array2 = new byte[5][];
				byte[][] array3 = new byte[5][];
				byte[] kvalflg = new byte[5];
				array2[0] = m_authTerminal;
				array3[0] = m_terminalName;
				array2[1] = m_authProgramName;
				array3[1] = m_programName;
				array2[2] = m_authMachine;
				array3[2] = m_hostName;
				array2[3] = m_authPid;
				array3[3] = m_processId;
				if (m_userName != null)
				{
					array2[4] = m_authSid;
					array3[4] = m_userName;
				}
				m_marshallingEngine.MarshalUB4(array2.Length);
				m_marshallingEngine.MarshalPointer();
				m_marshallingEngine.MarshalPointer();
				if (array != null)
				{
					m_marshallingEngine.MarshalCHR(array);
				}
				m_marshallingEngine.MarshalKEYVAL(array2, array3, kvalflg, array2.Length);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOSessKeyMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOSessKeyMessage);
				}
			}
		}

		internal void ReadOSessKeyResponse()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReadOSessKeyResponse);
			}
			byte[][] array = null;
			byte[][] array2 = null;
			int[] array3 = new int[0];
			try
			{
				m_marshallingEngine.TTCErrorObject.Initialize();
				bool flag = false;
				while (!flag)
				{
					try
					{
						switch ((byte)m_marshallingEngine.UnmarshalUB1())
						{
						case 23:
							ProcessServerSidePiggybackFunction(0);
							break;
						case 8:
						{
							int num = m_marshallingEngine.UnmarshalUB2();
							if (num > 0)
							{
								array = new byte[num][];
								array2 = new byte[num][];
								array3 = m_marshallingEngine.UnmarshalKEYVAL(array, array2, num);
							}
							break;
						}
						case 15:
							m_marshallingEngine.TTCErrorObject.ReadWarning();
							break;
						case 4:
							m_marshallingEngine.TTCErrorObject.ReadErrorMessage();
							if (m_marshallingEngine.TTCErrorObject.ErrorCode != 0)
							{
								return;
							}
							flag = true;
							break;
						default:
							throw new Exception("ReadOSessKeyResponse: TTC Error");
						}
					}
					catch (NetworkException ex)
					{
						if (ex.ErrorCode != 3111)
						{
							throw;
						}
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
					catch (Exception)
					{
						if (m_marshallingEngine.m_oraBufRdr != null)
						{
							m_marshallingEngine.m_oraBufRdr.ClearState();
						}
						m_marshallingEngine.m_oracleCommunication.Break();
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
				}
				if (array == null || array.Length < 1)
				{
					throw new Exception("ReadOSessKeyResponse: TTC Error");
				}
				bool flag2 = false;
				bool flag3 = false;
				bool flag4 = false;
				bool flag5 = false;
				bool flag6 = false;
				for (int i = 0; i < array.Length; i++)
				{
					if (!flag3 && HelperClass.CompareBytes(array[i], m_authVerifierData) == 0)
					{
						m_salt = array2[i];
						m_verifierType = array3[i];
						flag3 = true;
					}
					else if (!flag2 && HelperClass.CompareBytes(array[i], m_authSessionKey) == 0)
					{
						m_encryptedSK = array2[i];
						flag2 = true;
					}
					else if (!flag4 && HelperClass.CompareBytes(array[i], m_auth_pbkdf2_csk_salt) == 0)
					{
						byte[] array4 = array2[i];
						flag4 = true;
						if (array4.Length != 32)
						{
							throw new OracleException(28041, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesgWithErrCode(28041));
						}
						m_pbkdf2_cskSalt = array4;
					}
					else if (!flag5 && HelperClass.CompareBytes(array[i], m_auth_pbkdf2_vgen_count) == 0)
					{
						byte[] bytes = array2[i];
						flag5 = true;
						m_pbkdf2_vgen_count = int.Parse(Encoding.ASCII.GetString(bytes));
						if (m_pbkdf2_vgen_count < 4096 || m_pbkdf2_vgen_count > 100000000)
						{
							m_pbkdf2_vgen_count = 4096;
						}
					}
					else if (!flag6 && HelperClass.CompareBytes(array[i], m_auth_pbkdf2_sder_count) == 0)
					{
						byte[] bytes2 = array2[i];
						flag6 = true;
						m_pbkdf2_sder_count = int.Parse(Encoding.ASCII.GetString(bytes2));
						if (m_pbkdf2_sder_count < 3 || m_pbkdf2_sder_count > 100000000)
						{
							m_pbkdf2_sder_count = 3;
						}
					}
				}
				if (m_encryptedSK == null || (m_encryptedSK.Length != 64 && m_encryptedSK.Length != 96))
				{
					throw new Exception("ReadOSessKeyResponse: TTC Error: SessionKey should be either 64 or 96 bytes long.");
				}
			}
			catch (Exception ex3)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReadOSessKeyResponse, ex3);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReadOSessKeyResponse);
				}
			}
		}

		internal void EncryptNewPassword(SecureString secureNewPassword)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.EncryptNewPassword);
			}
			string pwdEncStr = "AES/CBC/PKCS5Padding";
			try
			{
				m_newEncryptedPassword = null;
				byte[] confounder = null;
				O5LogonHelper.ProcessNewPassword(m_marshallingEngine.m_dbCharSetConv, pwdEncStr, secureNewPassword, m_xoredKaAndKb, out m_newEncryptedPassword, ref confounder);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.EncryptNewPassword, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.EncryptNewPassword);
				}
			}
		}

		internal void WriteOAuthMessage(string userName, SecureString securePassword, string proxyClientName, bool bProxyAuth, int sessionId, int serialNum, long logonMode, SecureString secureNewPassword, byte logonCompatibility, bool bExternalAuth, bool bSendJDWP, string clientCharSet)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage);
			}
			byte[] userName2 = null;
			try
			{
				if (userName != null && userName.Length > 0)
				{
					userName2 = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(userName, 0, userName.Length);
					O5LogonHelper.DoLogonProcessing(m_marshallingEngine.m_dbCharSetConv, m_verifierType, m_salt, logonCompatibility, userName, securePassword, m_encryptedSK, m_pbkdf2_cskSalt, m_pbkdf2_vgen_count, m_pbkdf2_sder_count, m_marshallingEngine.m_bSvrCSMultibyte, out m_encryptedKB, out m_encryptedPassword, out m_xoredKaAndKb, out m_conFounder, out m_pbkdf2_speedy_key);
					if (!bExternalAuth && m_encryptedPassword == null)
					{
						m_encryptedPassword = new byte[64];
					}
					if (secureNewPassword != null)
					{
						EncryptNewPassword(secureNewPassword);
					}
				}
				DoMarshalOauth(userName2, logonMode, proxyClientName, bProxyAuth, sessionId, serialNum, bExternalAuth, bSendJDWP, clientCharSet);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage);
				}
			}
		}

		private void DoMarshalOauth(byte[] userName, long logonMode, string proxyClientName, bool bProxyAuth, int sessionId, int serialNum, bool bExternalAuth, bool bSendJDWP, string clientCharSet)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				string text = string.Empty;
				if (m_marshallingEngine != null)
				{
					text = "(DRCPConnection=" + m_marshallingEngine.m_bDRCPConnection + ")";
					if (m_marshallingEngine.m_bDRCPConnection && m_marshallingEngine.m_connImplReference != null)
					{
						text = text + "(drcpconnectionclasss=" + m_marshallingEngine.m_connImplReference.DRCPConnectionClass + ")";
					}
				}
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage, text);
			}
			try
			{
				m_functionCode = 115;
				WriteFunctionHeader();
				if (userName != null && userName.Length != 0)
				{
					m_marshallingEngine.MarshalPointer();
					m_marshallingEngine.MarshalSB4(userName.Length);
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
					m_marshallingEngine.MarshalSB4(0);
				}
				if (bProxyAuth)
				{
					logonMode |= 0x400;
				}
				if (userName != null && userName.Length != 0 && m_encryptedPassword != null)
				{
					logonMode |= 0x100;
				}
				m_marshallingEngine.MarshalUB4(logonMode);
				m_marshallingEngine.MarshalPointer();
				byte[][] array = new byte[30][];
				byte[][] array2 = new byte[30][];
				byte[] array3 = new byte[30];
				int num = 0;
				if (m_encryptedKB != null)
				{
					array[num] = m_authSessionKey;
					array2[num] = m_encryptedKB;
					array3[num++] = 1;
				}
				if (m_encryptedPassword != null)
				{
					array[num] = m_authPassword;
					array2[num++] = m_encryptedPassword;
				}
				if (m_newEncryptedPassword != null)
				{
					array[num] = m_authNewPassword;
					array2[num++] = m_newEncryptedPassword;
				}
				if (m_pbkdf2_speedy_key != null)
				{
					array[num] = m_auth_pbkdf2_speedy_key;
					array2[num++] = m_pbkdf2_speedy_key;
				}
				string text2 = ConfigBaseClass.OraDebugJDWP();
				if (bSendJDWP && !string.IsNullOrEmpty(text2))
				{
					byte[] valueToEncrypt = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text2, 0, text2.Length);
					byte[] array4 = O5LogonHelper.EncryptOraAuthJDWPValue(bExternalAuth, m_marshallingEngine.m_oracleCommunication.m_sessionCtx.m_hisone, m_xoredKaAndKb, valueToEncrypt);
					array[num] = m_authDebugJDWPValue;
					array2[num++] = array4;
				}
				array[num] = m_authTerminal;
				array2[num++] = m_terminalName;
				array[num] = m_authProgramName;
				array2[num++] = m_programName;
				array[num] = m_authMachine;
				array2[num++] = m_hostName;
				array[num] = m_authPid;
				array2[num++] = m_processId;
				if (m_userName != null)
				{
					array[num] = m_authSid;
					array2[num++] = m_userName;
				}
				array[num] = m_authConnectString;
				array2[num++] = m_connectstring;
				array[num] = m_sessionClientCharSet;
				array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(clientCharSet, 0, clientCharSet.Length);
				array[num] = m_sessionClientLibType;
				array2[num++] = m_clientLibType;
				array[num] = m_sessionClientDriverName;
				array2[num++] = m_clientDriverName;
				array[num] = m_sessionClientVersion;
				array2[num++] = m_clientVersion;
				array[num] = m_sessionClientLobAttr;
				array2[num++] = m_clientLobAttr;
				string editionName = m_marshallingEngine.m_connImplReference.m_editionName;
				if (!string.IsNullOrEmpty(editionName))
				{
					array[num] = m_authOraEditionAttr;
					array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(editionName, 0, editionName.Length);
				}
				if (m_marshallingEngine.m_bDRCPConnection)
				{
					string dRCPConnectionClass = m_marshallingEngine.m_connImplReference.DRCPConnectionClass;
					if (!string.IsNullOrEmpty(dRCPConnectionClass))
					{
						array[num] = m_drcpConnectionClass;
						array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(dRCPConnectionClass, 0, dRCPConnectionClass.Length);
					}
					string dRCPtagName = m_marshallingEngine.m_connImplReference.DRCPtagName;
					if (!string.IsNullOrEmpty(dRCPtagName))
					{
						array[num] = m_drcpTag;
						array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(dRCPtagName, 0, dRCPtagName.Length);
						if (m_marshallingEngine.m_connImplReference.m_bDRCPUseMultitag)
						{
							array[num] = m_drcpMultipropTag;
							array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes("TRUE", 0, "TRUE".Length);
						}
					}
					string drcpSessionPurity = m_marshallingEngine.m_connImplReference.m_drcpSessionPurity;
					if (!string.IsNullOrEmpty(drcpSessionPurity))
					{
						array[num] = m_drcpSessionPurity;
						array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(drcpSessionPurity, 0, drcpSessionPurity.Length);
					}
					string drcpPLSQLCallback = m_marshallingEngine.m_connImplReference.m_drcpPLSQLCallback;
					if (!string.IsNullOrEmpty(drcpPLSQLCallback) && m_marshallingEngine.NegotiatedTTCVersion >= 8)
					{
						array[num] = m_drcpFixupCB;
						array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(drcpPLSQLCallback, 0, drcpPLSQLCallback.Length);
					}
				}
				if (m_authAlterSession != null)
				{
					array[num] = m_authAlterSession;
					array2[num] = m_alterSessionSql;
					array3[num++] = 1;
				}
				if (!string.IsNullOrEmpty(proxyClientName))
				{
					array[num] = m_authProxyClientName;
					array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(proxyClientName, 0, proxyClientName.Length);
				}
				if (sessionId != -1)
				{
					array[num] = m_authSessionId;
					array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(sessionId.ToString(), 0, sessionId.ToString().Length);
				}
				if (serialNum != -1)
				{
					array[num] = m_authSerialNum;
					array2[num++] = m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(serialNum.ToString(), 0, serialNum.ToString().Length);
				}
				m_marshallingEngine.MarshalUB4(num);
				m_marshallingEngine.MarshalPointer();
				m_marshallingEngine.MarshalPointer();
				if (userName != null && userName.Length != 0)
				{
					m_marshallingEngine.MarshalCHR(userName);
				}
				m_marshallingEngine.MarshalKEYVAL(array, array2, array3, num);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.WriteOAuthMessage);
				}
			}
		}

		internal bool ReceiveOAuthResponse()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReceiveOAuthResponse);
			}
			byte[][] array = null;
			byte[][] array2 = null;
			int num = 0;
			bool result = false;
			try
			{
				m_marshallingEngine.TTCErrorObject.Initialize();
				m_sessionProperties = new Hashtable();
				bool flag = false;
				while (!flag)
				{
					try
					{
						switch ((byte)m_marshallingEngine.UnmarshalUB1())
						{
						case 23:
						{
							byte b = (byte)m_marshallingEngine.UnmarshalUB1();
							if (b == 5)
							{
								m_marshallingEngine.UnmarshalUB2(bIgnoreData: true);
								m_marshallingEngine.UnmarshalUB1(bIgnoreData: true);
								ProcessOCSSYNCMessage(m_sessionProperties);
							}
							else
							{
								ProcessServerSidePiggybackFunction(b);
							}
							break;
						}
						case 8:
						{
							num = m_marshallingEngine.UnmarshalUB2();
							if (num <= 0)
							{
								break;
							}
							array = new byte[num][];
							array2 = new byte[num][];
							m_marshallingEngine.UnmarshalKEYVAL(array, array2, num);
							string empty = string.Empty;
							string empty2 = string.Empty;
							for (int i = 0; i < num; i++)
							{
								if (array[i] != null)
								{
									empty = m_marshallingEngine.m_dbCharSetConv.ConvertBytesToString(array[i], 0, array[i].Length).Trim('\0');
									if (empty != "AUTH_SVR_RESPONSE")
									{
										empty2 = ((array2[i] == null) ? string.Empty : m_marshallingEngine.m_dbCharSetConv.ConvertBytesToString(array2[i], 0, array2[i].Length));
										m_sessionProperties[empty] = empty2;
									}
									else
									{
										m_sessionProperties[empty] = array2[i];
									}
								}
							}
							break;
						}
						case 15:
							m_marshallingEngine.TTCErrorObject.ReadWarning();
							break;
						case 4:
							m_marshallingEngine.TTCErrorObject.ReadErrorMessage();
							if (m_marshallingEngine.TTCErrorObject.ErrorCode != 0)
							{
								return false;
							}
							flag = true;
							break;
						default:
							throw new Exception("ReceiveOAuthResponse: TTC Error");
						}
					}
					catch (NetworkException ex)
					{
						if (ex.ErrorCode != 3111)
						{
							throw;
						}
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
					catch (Exception)
					{
						if (m_marshallingEngine.m_oraBufRdr != null)
						{
							m_marshallingEngine.m_oraBufRdr.ClearState();
						}
						m_marshallingEngine.m_oracleCommunication.Break();
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
				}
				byte[] msgHex = (byte[])m_sessionProperties["AUTH_SVR_RESPONSE"];
				byte[] array3 = O5LogonHelper.EvaluateServerResponse("AES/CBC/PKCS5Padding", m_xoredKaAndKb, msgHex);
				byte[] array4 = null;
				if (array3 != null && array3.Length >= 16)
				{
					array4 = new byte[16];
					Array.Copy(array3, 16, array4, 0, 16);
				}
				if (array4 == null || HelperClass.CompareBytes(KZSR_SVR_RESPONSE, array4) != 0)
				{
					result = true;
				}
				return result;
			}
			catch (Exception ex3)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReceiveOAuthResponse, ex3);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCAuthenticate, OracleTraceFuncName.ReceiveOAuthResponse);
				}
			}
		}

		internal static string ConvertVersionIntToString(MarshallingEngine mEngine, int dbRawVersion, ref int dbMajorVer, ref int dbMinorVer, ref int dbPatchsetVer)
		{
			int num = 0;
			int num2 = 0;
			dbMajorVer = (dbRawVersion >> 24) & 0xFF;
			if (mEngine.NegotiatedTTCVersion >= 11)
			{
				dbMinorVer = (dbRawVersion >> 16) & 0xFF;
				num = (dbRawVersion >> 12) & 0xF;
				dbPatchsetVer = (dbRawVersion >> 4) & 0xFF;
				num2 = dbRawVersion & 0xF;
			}
			else
			{
				dbMinorVer = (dbRawVersion >> 20) & 0xF;
				num = (dbRawVersion >> 12) & 0xFF;
				dbPatchsetVer = (dbRawVersion >> 8) & 0xF;
				num2 = dbRawVersion & 0xFF;
			}
			return dbMajorVer + "." + dbMinorVer + "." + num + "." + dbPatchsetVer + "." + num2;
		}

		internal int ClientVersionStringToInt(string driverVersion)
		{
			int result = 0;
			try
			{
				string[] array = driverVersion.Split(m_versionSeparator);
				int num = int.Parse(array[2]);
				int num2 = int.Parse(array[3]);
				int num3 = 0;
				int num4 = 0;
				int num5 = 0;
				result = (num << 24) | (num2 << 16) | (num3 << 12) | (num4 << 8) | num5;
				return result;
			}
			catch
			{
				return result;
			}
		}
	}
}
